package com.smaxll.sudoku;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;

import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;


public class Sudoku extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //set up click listener for all the buttons
        View continueButton = findViewById(R.id.btn_continue);
        continueButton.setOnClickListener(this);
        View newGameButton = findViewById(R.id.btn_newGame);
        newGameButton.setOnClickListener(this);
        View optionsButton = findViewById(R.id.btn_options);
        optionsButton.setOnClickListener(this);
        View aboutButton = findViewById(R.id.btn_about);
        aboutButton.setOnClickListener(this);
        View exitButton = findViewById(R.id.btn_exit);
        exitButton.setOnClickListener(this);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);
        
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch(item.getItemId()){
        case R.id.settings: 
            startActivity(new Intent(this, Prefs.class));
            return true;
        }
        return false;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()){
        case R.id.btn_newGame:
            openNewGameDialog();
            break;
        case R.id.btn_about:
            Intent i = new Intent(this, About.class);
            startActivity(i);
            break;
        case R.id.btn_exit:
            finish();
            break;
        }
    }

    private void openNewGameDialog() {
        // TODO Auto-generated method stub
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        
        builder.setTitle("Sudoku Difficulties");
        builder.setItems(R.array.difficulty, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int item){
                startGame(item);
            }

        });
        builder.show();
    }
    
    private void startGame(int item) {
        // TODO Auto-generated method stub
        Log.d("Sudoku", "clicked on " + item);

    }
    
}